package oauth

import "sync"

var stateCodeCache = new(StateCache)

type StateCache struct {
	cache sync.Map //map[string]struct{}
}

//Add store stateCode to StateCache
func (sc *StateCache) Add(stateCode string) {
	sc.cache.Store(stateCode, struct{}{})
}

//RemoveIfExists remove stateCode from StateCache, if the key was present return true else return false
func (sc *StateCache) RemoveIfExists(stateCode string) bool {
	_, ok := sc.cache.LoadAndDelete(stateCode)
	return ok
}
